import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import styleImport from 'vite-plugin-style-import'

import { resolve } from 'path'

function pathResolve(dir: string) {
  return resolve(process.cwd(), '.', dir)
}
//console.log('---', process.env)

// function pathResolve(dir: string) {
//   return resolve(__dirname, ".", dir);
// }

export default (params) => {

  console.log(params.mode)

  const __DEV__ = params.mode === 'development';
  return defineConfig({
    base: __DEV__ ? '/' : '/', //判断是什么环境
    resolve: {
      alias: {
        '@': pathResolve("src"),
      }
    },
    css: {
      modules: false,
      preprocessorOptions: {
        scss: {
          additionalData: '@import "@/style/var.scss";'
        }
      }
    },
    plugins: [
      vue({})
    ],
    server: {
      host: '0.0.0.0',
      port: 8080,
      hmr: { overlay: false }
    }

  })

}
